package com.free.semantic.core.subconcept.impl;

import com.free.semantic.common.*;
import com.free.semantic.core.ConceptInstanceManage;
import com.free.semantic.core.ConceptManage;
import com.free.semantic.core.impl.ConceptInstanceManageImpl;
import com.free.semantic.core.subconcept.SubConceptInstanceProvider;
import com.free.semantic.req.RelationDefineGroup;

import java.util.List;

import static com.free.semantic.utils.Utils.*;
import static com.free.semantic.utils.Utils.createRelation;

public class Temperature implements SubConceptInstanceProvider {


    @Override
    public String getName() {
        return "温度转换";
    }

    @Override
    public ConceptInstanceManage getInstanceMange() {

        RelationDefineGroup group1 = new RelationDefineGroup();
        // relation 包含(A,B)
        defineRelation(group1, "找到", defineItem(oneObj("A"), oneObj("B"))); // B->A=1 //代表 针对任意一个B，都可以找到 1个A与之对应

        ConceptManage model1 = getConceptManage(group1);
        object(model1, "摄氏温度", "绝对温度2");
        createRelation(model1, "找到", "绝对温度2", "摄氏温度");
        ConceptInstanceManage modelInstance = new ConceptInstanceManageImpl(model1);
        modelInstance.registerFunction(Ls.of("绝对温度2"), "摄氏温度", context -> {
            List<Object> value = context.getListValue("绝对温度2");
            Float temp = Float.parseFloat(value.get(0).toString());
            float newTemp = temp - 273;
            context.setValue("摄氏温度", newTemp);
        });
        return modelInstance;
    }
}
